package com.skycong.skycongtool;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

public class Http {


    /**
     * 测试使用 从app里面调用 tool里面的 http
     *
     * @param url
     * @return
     * @throws IOException
     */
    public static String get(String url) throws IOException {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().get().url(url).build();
//        同步请求
        Response response = client.newCall(request).execute();
        String string = null;
        if (response.isSuccessful()) {
            string = response.body().string();
            System.out.println("服务器相应的字符串是 = " + string);
        }
        return string;
    }
}
